<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2007 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id: common.php 2601 2012-01-15 04:59:14Z liu21st $

/**
 +----------------------------------------------------------
 * 格式化日期时间
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param	string	$str	日期时间
 * @param	string	$format	日期时间格式
 * @return	string
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
function toDate($str,$format='Y-m-d H:i:s'){
	$str = trim($str);
	if(!$str) return false;
	$date = strtotime($str);
	if(!$date) return $str;
	$date = date($format,$date);
	if(strpos($date,'1970')===1) return $str;
	return $date;
}

/** 数组生成OPTION
 * @param	array	$arr	显示列表
 * @param	string	$val	选中项的值
 * @param	boolean	$return	是否返回
 * @return	string
 */
function show_arr_opt($arr, $val=null, $return=true){
	if(!is_array($arr)) return false;
	$re_str = '';
	foreach($arr as $key => $var){
		$re_str .= '<option value="'.$key.'"';
		if("$val"==="$key") $re_str .= ' selected ';
		$re_str .= '>';
		$re_str .= $var;
		$re_str .= '</option>';
	}
	if($return) return $re_str;
	echo $re_str;
}

?>